package com.xiaoye.qbproject.service.impl;

import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoye.qbproject.domain.*;
import com.xiaoye.qbproject.exception.ServiceException;
import com.xiaoye.qbproject.mapper.*;
import com.xiaoye.qbproject.redis.RedisCache;
import com.xiaoye.qbproject.redis.RedisConstant;
import com.xiaoye.qbproject.service.ZbInfoService;
import com.xiaoye.qbproject.vo.ZbAttrImportVo;
import com.xiaoye.qbproject.vo.ZbImportV2Vo;
import com.xiaoye.qbproject.vo.ZbImportVo;
import com.xiaoye.qbproject.vo.ZbInfoVo;
import com.xiaoye.qbproject.vo.dropDown.ZbInfoDropDownVO;
import io.jsonwebtoken.lang.Collections;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.jena.ontology.*;
import org.apache.jena.rdf.model.ModelFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @description 针对表【ZB_INFO(装备信息)】的数据库操作Service实现
 * @createDate 2024-12-27 02:57:47
 */
@Slf4j
@Service
public class ZbInfoServiceImpl extends ServiceImpl<ZbInfoMapper, ZbInfo>
        implements ZbInfoService {
    @Autowired
    private ZbInfoMapper zbInfoMapper;
    @Autowired
    private ZbTypeMapper zbTypeMapper;
    @Autowired
    private ZbModuleMapper zbModuleMapper;
    @Autowired
    private CountryRegionMapper countryRegionMapper;
    @Autowired
    private RedisCache redisCache;

    private static void addZbInfoToModel(OntModel model, OntClass zbInfoClass, OntProperty hasAttributeProperty, ZbInfo zbInfo, String ns) {
        // 为当前zbInfo实例创建个体
        Individual individual = model.createIndividual(ns + zbInfo.getId(), zbInfoClass);
        List<ZbAttr> attrs = JSONArray.parseArray(JSONArray.toJSONString(zbInfo.getAttrs()), ZbAttr.class);
        // 遍历zbInfo的属性列表，并为每个属性创建个体，设置hasAttribute关系
        for (ZbAttr attr : attrs) {
            Individual attrIndividual = model.createIndividual(ns + "attrName" + attr.hashCode(), model.createClass(ns + "ZbAttr"));
            // 可以为attrIndividual添加其他属性或注释来描述这个属性
            attrIndividual.addProperty(model.createOntProperty(ns + "attrName"), attr.getAttrName() + org.apache.commons.lang3.StringUtils.join(attr.getAttrs(), ","));
            //attrIndividual.addProperty(model.createOntProperty(ns + attr.getAttrName().replaceAll(" ", "").replaceAll("[^\\p{L}0-9]", "")), org.apache.commons.lang3.StringUtils.join(attr.getAttrs(), ","));
            model.add(individual, hasAttributeProperty, attrIndividual);
        }
    }

    /**
     * @param result
     * @param countryName
     * @description: 批量导入装备信息，包括装备类型和模块信息
     * @author: ChenYao
     * @return: void
     * @ceateDate: 2024-12-27 14:37
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveZbAndTypeAndModules(List<ZbImportVo> result, String countryName) {
        // 查询所有装备类型
        List<ZbType> zbTypes = zbTypeMapper.selectList(Wrappers.query());
        // 转成map对象 key:zbTypeName value:id
        HashMap<String, String> zbTypeMap = new HashMap<>();
        zbTypes.forEach(zbType -> zbTypeMap.put(zbType.getName(), zbType.getId()));

        // 查询所有装备信息
        List<ZbInfo> zbInfos = zbInfoMapper.selectList(Wrappers.query());
        HashMap<String, String> zbInfoMap = new HashMap<>();
        zbInfos.forEach(zbInfo -> zbInfoMap.put(zbInfo.getName(), zbInfo.getId()));

        // 查询所有装备组件信息
        List<ZbModule> zbModules = zbModuleMapper.selectList(Wrappers.query());
        HashMap<String, String> zbModuleMap = new HashMap<>();
        // 这里因为组件名称会有重名的.没办法
        zbModules.forEach(zbModule -> zbModuleMap.put(zbModule.getName() + "_" + zbModule.getNum(), zbModule.getId()));
        // 查询国家信息
        CountryRegion countryRegion = countryRegionMapper.selectOne(Wrappers.<CountryRegion>lambdaQuery().like(CountryRegion::getName, countryName).last("limit 1"));
        if (countryRegion == null) {
            throw new ServiceException(countryName + ",国家信息不存在");
        }
        // 新增父类的配置信息,同时把id设置进去
        for (ZbImportVo zbImportVo : result) {
            // 判断装备类型是否存在
            String zbTypeName = zbImportVo.getZbTypeName();
            if (StringUtils.isNotBlank(zbTypeName)) {
                ZbType zbType = new ZbType();
                zbType.setName(zbTypeName.trim());
                if (!zbTypeMap.containsKey(zbTypeName)) {
                    // 不存在，新增装备类型
                    zbTypeMapper.insert(zbType);
                } else {
                    zbType.setId(zbTypeMap.get(zbTypeName));
                    zbTypeMapper.updateById(zbType);
                }
                zbTypeMap.put(zbType.getName(), zbType.getId());
                zbImportVo.setZbTypeId(zbType.getId());
            }

            // 判断装备信息是否存在
            String zbName = zbImportVo.getZbName();
            if (StringUtils.isNotBlank(zbName)) {
                ZbInfo zbInfo = new ZbInfo();
                zbInfo.setType(zbImportVo.getZbTypeId());
                zbInfo.setName(zbName.trim());
                //zbInfo.setFeature(zbImportVo.getFeature());
                zbInfo.setSourceCountryId(countryRegion.getId());
                zbInfo.setAttrsByFeature(zbImportVo.getFeature());
                zbInfo.setRemark(zbImportVo.getZbModuleRemark());
                // 不存在，新增装备信息
                if (!zbInfoMap.containsKey(zbName)) {
                    log.info("新增装备信息:{}", zbInfo);
                    zbInfoMapper.insert(zbInfo);
                } else {
                    zbInfo.setId(zbInfoMap.get(zbName));
                    // 存在，更新装备信息
                    log.info("更新装备信息:{}", zbInfo);
                    zbInfoMapper.updateById(zbInfo);
                }
                zbInfoMap.put(zbInfo.getName(), zbInfo.getId());
                zbImportVo.setZbId(zbInfo.getId());
            }


            String zbModuleName = zbImportVo.getZbModuleName();
            String zbModuleParameter = zbImportVo.getZbModuleParameter();
            String zbModuleNum = zbImportVo.getZbModuleNum();
            if (StringUtils.isBlank(zbModuleName) && StringUtils.isBlank(zbModuleNum) && StringUtils.isBlank(zbModuleParameter)) {
                log.error("装备组件信息缺失,截止添加组件信息,zbImportVo:{}", zbImportVo);
                continue;
            }
            ZbModule zbModule = new ZbModule();
            zbModule.setName(zbModuleName);
            zbModule.setNum(zbModuleNum);
            zbModule.setParameter(zbModuleParameter);
            zbModule.setRemark(zbImportVo.getZbModuleRemark());
            zbModule.setZbInfoId(zbImportVo.getZbId());
            String moduleKey = zbModuleName + "_" + zbModuleNum;
            if (zbModuleMap.containsKey(moduleKey)) {
                zbModule.setId(zbModuleMap.get(moduleKey));
                zbModuleMapper.updateById(zbModule);
                log.info("更新装备组件信息:{}", zbModule);
            } else {
                // 添加装备组件信息
                log.info("新增装备组件信息:{}", zbModule);
                zbModuleMapper.insert(zbModule);
                log.info("新增装备组件信息:{}", zbModule);
            }


        }

    }

    /**
     * @param zbAttrImportVos
     * @description: 装备数据导入
     * @author: ChenYao
     * @return: void
     * @ceateDate: 2024-12-31 14:14
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importZbAttrInfo(List<ZbAttrImportVo> zbAttrImportVos) {
        if (Collections.isEmpty(zbAttrImportVos)) {
            log.info("装备数据导入为空,不执行导入操作");
            return;
        }
        // 获取所有国家数据
        List<CountryRegion> countryRegions = countryRegionMapper.selectList(Wrappers.<CountryRegion>lambdaQuery().select(CountryRegion::getId, CountryRegion::getName));
        HashMap<String, String> countryMap = new HashMap<>();
        countryRegions.forEach(countryRegion -> countryMap.put(countryRegion.getName(), countryRegion.getId()));
        // 获取所有一级分类数据
        List<ZbType> zbTypes = zbTypeMapper.selectList(Wrappers
                .<ZbType>lambdaQuery()
                .eq(ZbType::getParentId, "0")
                .or().isNull(ZbType::getParentId)
                .select(ZbType::getId, ZbType::getName)
        );
        // 一级分类
        HashMap<String, String> zbTypeMap = new HashMap<>();
        zbTypes.forEach(zbType -> zbTypeMap.put(zbType.getName(), zbType.getId()));
        // 二级分类
        // 获取所有一级分类数据
        List<ZbType> zbTwoTypes = zbTypeMapper.selectList(Wrappers
                .<ZbType>lambdaQuery()
                .isNotNull(ZbType::getParentId)
                .select(ZbType::getId, ZbType::getName)
        );
        HashMap<String, String> zbTwoTypeMap = new HashMap<>();
        zbTwoTypes.forEach(zbType -> zbTwoTypeMap.put(zbType.getName(), zbType.getId()));
        // 获取所有装备信息
        List<ZbInfo> zbInfos = zbInfoMapper.selectList(Wrappers
                .<ZbInfo>lambdaQuery()
                .select(ZbInfo::getId, ZbInfo::getName, ZbInfo::getAttrs)
        );
        HashMap<String, ZbInfo> zbInfoMap = new HashMap<>();
        zbInfos.forEach(zbInfo -> zbInfoMap.put(zbInfo.getName(), zbInfo));
        for (ZbAttrImportVo zbAttrImportVo : zbAttrImportVos) {
            if (StringUtils.isBlank(zbAttrImportVo.getAttrName())) {
                continue;
            }
            // 判断国家是否存在

            // 国家不存在就新增国家信息,国家存在就更新国家ID
            String countryName = zbAttrImportVo.getCountryName();
            if (!countryMap.containsKey(countryName)) {
                // 新增国家信息
                CountryRegion countryRegion = new CountryRegion();
                countryRegion.setName(countryName);
                countryRegionMapper.insert(countryRegion);
                countryMap.put(countryRegion.getName(), countryRegion.getId());
            }
            // 更新国家ID
            zbAttrImportVo.setCountryId(countryMap.get(countryName));

            // 判断一级分类是否存在,不存在就新增分类,存在则更新分类id
            String zbTypeName = zbAttrImportVo.getZbTypeName();
            if (!zbTypeMap.containsKey(zbTypeName)) {
                // 新增一级分类信息
                ZbType zbType = new ZbType();
                zbType.setName(zbTypeName);
                zbTypeMapper.insert(zbType);
                zbTypeMap.put(zbType.getName(), zbType.getId());

            }
            // 更新一级分类ID
            zbAttrImportVo.setZbTypeId(zbTypeMap.get(zbTypeName));
            // 判断二级分类是否存在,不存在就新增分类,存在则更新分类id
            String zbTwoTypeName = zbAttrImportVo.getZbTwoTypeName();
            if (!zbTwoTypeMap.containsKey(zbTwoTypeName)) {
                // 新增二级分类信息
                ZbType zbType = new ZbType();
                zbType.setParentId(zbAttrImportVo.getZbTypeId());
                zbType.setName(zbTwoTypeName);
                zbTypeMapper.insert(zbType);
                zbTwoTypeMap.put(zbType.getName(), zbType.getId());
            }
            // 更新二级分类ID
            zbAttrImportVo.setZbTwoTypeId(zbTwoTypeMap.get(zbTwoTypeName));
            //

            // 判断装备信息是否存在
            String zbName = zbAttrImportVo.getZbName();

            if (!zbInfoMap.containsKey(zbName)) {
                ZbInfo zbInfo = new ZbInfo();
                zbInfo.setName(zbName);
                List<ZbAttr> attrList = new ArrayList<>();
                ZbAttr zbAttr = new ZbAttr();
                zbAttr.setAttrName(zbAttrImportVo.getAttrName());
                zbAttr.setAttrValueList(zbAttrImportVo.getAttrValue());
                attrList.add(zbAttr);
                zbInfo.setAttrs(attrList);
                // 新增装备信息
                zbInfoMapper.insert(zbInfo);
                zbInfoMap.put(zbInfo.getName(), zbInfo);
            } else {
                ZbInfo zbInfo = zbInfoMap.get(zbName);
                List<ZbAttr> attrs = zbInfo.getAttrs();
                // 没有一个属性,则直接添加
                if (Collections.isEmpty(attrs)) {
                    ZbAttr zbAttr = new ZbAttr();
                    zbAttr.setAttrName(zbAttrImportVo.getAttrName());
                    zbAttr.setAttrValueList(zbAttrImportVo.getAttrValue());
                    attrs.add(zbAttr);
                }
                boolean containsFlag = false;
                // 有属性则判断 属性key是否存在,不存在就添加一个属性,存在则更新属性值
                for (ZbAttr attr : attrs) {
                    if (attr.getAttrName().equals(zbAttrImportVo.getAttrName())) {
                        // 包含就更新属性值
                        attr.setAttrValueList(zbAttrImportVo.getAttrValue());
                        containsFlag = true;
                    }
                }
                if (!containsFlag) {
                    // 不包含就添加一个属性
                    ZbAttr zbAttr = new ZbAttr();
                    zbAttr.setAttrName(zbAttrImportVo.getAttrName());
                    zbAttr.setAttrValueList(zbAttrImportVo.getAttrValue());
                    attrs.add(zbAttr);
                }
                // 更新属性信息
                zbInfoMapper.updateById(zbInfo);
            }

        }

    }

    /**
     * @description: 下拉列表查询装备信息
     * @author: ChenYao
     * @return: java.util.List<com.xiaoye.qbproject.vo.dropDown.ZbInfoDropDownVO>
     * @ceateDate: 2025-01-02 14:09
     */
    @Override
    public List<ZbInfoDropDownVO> dropDown() {
        List<ZbInfoDropDownVO> dropDownVOS = redisCache.getCacheObject(RedisConstant.QB_ZB_DROPDOWN);
        if (dropDownVOS != null) {
            return dropDownVOS;
        }
        dropDownVOS = baseMapper.dropDown(null);
        redisCache.setCacheObject(RedisConstant.QB_ZB_DROPDOWN, dropDownVOS, 10, TimeUnit.MINUTES);
        return dropDownVOS;
    }

    @Autowired
    private SubjectZbMapper subjectZbMapper;

    /**
     * @description: 查询装备下拉列表信息(排除和专题已关联的)
     * @author: ChenYao
     * @return: java.util.List<com.xiaoye.qbproject.vo.dropDown.ZbInfoDropDownVO>
     * @ceateDate: 2025/2/11 下午3:39
     */
    @Override
    public List<ZbInfoDropDownVO> excludeRelateToDropDown(String subjectId) {
        // 查询已经关联的装备信息
        List<SubjectZb> subjectZbs = subjectZbMapper.selectList(Wrappers.lambdaQuery(SubjectZb.class).eq(SubjectZb::getSubjectId, subjectId));
        List<String> zbIds = subjectZbs.stream().map(SubjectZb::getZbId).collect(Collectors.toList());
        // 查询未关联的装备信息
        return baseMapper.dropDown(zbIds);
    }

    @Override
    public void delCache() {
        redisCache.deleteObject(RedisConstant.QB_ZB_DROPDOWN);
        redisCache.deleteObject(RedisConstant.QB_ZB);
    }

    /**
     * @param ids
     * @param response
     * @description: 导出owl 标准文件
     * @author: ChenYao
     * @return: void
     * @ceateDate: 2025-01-03 13:41
     */

    @SneakyThrows
    @Override
    public void exportOwl(String[] ids, HttpServletResponse response) {
        if (ids == null || ids.length == 0) {
            throw new ServiceException("请选择要导出的数据");
        }
        // 指定OWL文件的路径
        List<ZbInfo> zbInfos = baseMapper.selectList(Wrappers
                        .<ZbInfo>lambdaQuery()
                        .in(ZbInfo::getId, Arrays.asList(ids))
                //.last("limit 5")
        );
        if (Collections.isEmpty(zbInfos)) {
            return;
        }
// 初始化模型
        OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
        // 设置命名空间
        String ns = "http://example.com/zbInfo#";
        model.setNsPrefix("zb", ns);

        // 定义ZbInfo类
        OntClass zbInfoClass = model.createClass(ns + "ZbInfo");
        OntProperty nameProperty = model.createOntProperty(ns + "name");
        // 定义hasAttribute属性
        OntProperty hasAttributeProperty = model.createOntProperty(ns + "hasAttribute");

        // 假设zbInfos已经初始化并填充了数据

        // 将zbInfos数据添加到模型中
        for (ZbInfo zbInfo : zbInfos) {
            Individual individual = model.createIndividual(ns + zbInfo.getId(), zbInfoClass);
            individual.addProperty(nameProperty, zbInfo.getName());
            addZbInfoToModel(model, zbInfoClass, hasAttributeProperty, zbInfo, ns);
        }

/*        // 创建一个空的模型
        Model model = ModelFactory.createDefaultModel();

        // 创建一个本体（这里以匿名本体为例）
        OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model);

        // 定义命名空间（这里以示例命名空间为例）
        String ns = "http://example.com/zbInfos#";
        ontModel.setNsPrefix("zb", ns);

        // 定义类
        OntClass zbClass = ontModel.createClass(ns + "ZbInfo");

        // 定义属性
        OntProperty nameProperty = ontModel.createOntProperty(ns + "name");
        OntProperty valueProperty = ontModel.createOntProperty(ns + "feature");


        // 假设zbInfos是一个包含数据的集合


        // 创建个体并填充数据
        for (ZbInfo zbInfo : zbInfos) {
            Individual individual = ontModel.createIndividual(ns + zbInfo.getId(), zbClass);
            individual.addProperty(nameProperty, zbInfo.getName());
            individual.addProperty(valueProperty, zbInfo.getFeature());
            zbInfo.getAttrs().forEach(zbAttr -> {
                OntProperty attrName = ontModel.createOntProperty(ns + zbAttr.getAttrName());
                individual.addProperty(attrName, zbAttr.getAttrs().toString());
            });
        }*/
        // 将本体写入文件
        try (ServletOutputStream outputStream = response.getOutputStream()
        ) {
            model.write(outputStream, "RDF/XML-ABBREV"); // 使用RDF/XML格式导出
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param zbInfoVo
     * @description: 根据条件查询装备信息列表
     * @author: ChenYao
     * @return: java.util.List<com.xiaoye.qbproject.domain.ZbInfo>
     * @ceateDate: 2025-01-10 13:03
     */
    @Override
    public List<ZbInfo> getZbInfoList(ZbInfoVo zbInfoVo) {
        return baseMapper.getZbInfoList(zbInfoVo);
    }

    /**
     * @param id
     * @description: 获取装备详情
     * @author: ChenYao
     * @return: com.xiaoye.qbproject.domain.ZbInfo
     * @ceateDate: 2025-01-10 13:42
     */
    @Override
    public ZbInfo getZbInfo(String id) {
        return baseMapper.getZbInfo(id);
    }

    /**
     * @param zbImportVos
     * @param countryName
     * @description: 批量导入装备信息V2版本
     * @author: ChenYao
     * @return: void
     * @ceateDate: 2025-01-13 19:03
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveZbInfoV2(List<ZbImportV2Vo> zbImportVos, String countryName) {
        if (Collections.isEmpty(zbImportVos)) {
            log.error("装备导入数据为空");
            return;
        }
        CountryRegion countryRegion = countryRegionMapper.selectOne(Wrappers.<CountryRegion>lambdaQuery().eq(CountryRegion::getName, countryName).last("limit 1"));
        if (countryRegion == null && !countryName.contains("Sheet")) {
            countryRegion = new CountryRegion();
            countryRegion.setName(countryName);
            countryRegionMapper.insert(countryRegion);
        }
        // 国家id
        String id = countryRegion != null ? countryRegion.getId() : null;
        // 获取所有装备类型
        List<ZbType> oldZbTypes = zbTypeMapper.selectList(Wrappers.lambdaQuery());
        Map<String, ZbType> oldZbTypeMap = new HashMap<>();
        for (ZbType zbType : oldZbTypes) {
            oldZbTypeMap.put(zbType.getName(), zbType);
        }
        // 获取所有装备
        List<ZbInfo> oldZbInfos = baseMapper.selectList(Wrappers.<ZbInfo>lambdaQuery().select(ZbInfo::getId, ZbInfo::getName, ZbInfo::getType));
        // 装备map
        HashMap<String, ZbInfo> oldZbInfoMap = new HashMap<>();
        oldZbInfos.forEach(e -> oldZbInfoMap.put(e.getName(), e));

        for (ZbImportV2Vo zbImportVo : zbImportVos) {
            String name = zbImportVo.getName();
            if (StringUtils.isBlank(name)) {
                continue;
            }
            // 需要入库的装备数据
            ZbInfo needAddOrUpdateZbInfo = new ZbInfo();
            BeanUtils.copyProperties(zbImportVo, needAddOrUpdateZbInfo);
            needAddOrUpdateZbInfo.setAttrsByFeature(zbImportVo.getFeature());
            needAddOrUpdateZbInfo.setName(name.trim());
            //zbInfo.setFeature(zbImportVo.getFeature());
            needAddOrUpdateZbInfo.setSourceCountryId(countryRegion.getId());
            needAddOrUpdateZbInfo.setSourceCountryId(id);
            // 父级类型
            String zbParentTypeName = zbImportVo.getParentTypeName();
            ZbType parentZbType = null;
            // 存在父级类型
            if (StringUtils.isNotBlank(zbParentTypeName)) {
                // 获取父级类型
                parentZbType = oldZbTypeMap.get(zbParentTypeName);
                if (parentZbType == null) {
                    // 不存在,新增父类型
                    parentZbType = new ZbType();
                    parentZbType.setName(zbParentTypeName);
                    zbTypeMapper.insert(parentZbType);
                    oldZbTypeMap.put(zbParentTypeName, parentZbType);
                }
            }

            // 子级类型
            String zbTypeName = zbImportVo.getTypeName();
            if (StringUtils.isNotBlank(zbTypeName)) {
                ZbType zbType = oldZbTypeMap.get(zbTypeName);
                if (zbType == null) {
                    // 所在类型不存在,新增类型
                    zbType = new ZbType();
                    if (parentZbType != null) {
                        zbType.setParentId(parentZbType.getId());
                    }
                    zbType.setName(zbTypeName);
                    zbTypeMapper.insert(zbType);
                    // 设置装备类型id
                    oldZbTypeMap.put(zbTypeName, zbType);
                }
                needAddOrUpdateZbInfo.setType(zbType.getId());
            }


            // 是否存在的装备,存在则更新,不存在则添加
//            ZbInfo oldZbInfo = oldZbInfoMap.get(name);
//            if (oldZbInfo != null) {
//                needAddOrUpdateZbInfo.setId(oldZbInfo.getId());
//                // 更新装备信息
//                baseMapper.updateById(needAddOrUpdateZbInfo);
//            } else {
                // 新增装备信息
                baseMapper.insert(needAddOrUpdateZbInfo);
//            }
            oldZbInfoMap.put(needAddOrUpdateZbInfo.getName(), needAddOrUpdateZbInfo);
        }


    }

    private String getCountryName(String country) {
        if (StringUtils.isBlank(country)) {
            return null;
        }
        if (country.contains("美")) {
            return "美国";
        }
        if (country.contains("印")) {
            return "印度";
        }
        if (country.contains("俄")) {
            return "俄罗斯";
        }
        if (country.contains("台")) {
            return "台湾地区";
        }
        if (country.contains("韩")) {
            return "韩国";
        }
        if (country.contains("中")) {
            return "中国";
        }
        return country;

    }
}




